<?php
class Pageley_Gateway_Database_EntityResultSetExtractor implements Pageley_Gateway_Database_ResultSetExtractor {
    private $type;
    private $tableName;
    
    public function __construct($type, $tableName) {
        $this->type = $type;
        $this->tableName = $tableName;
    }
    
    public function extractResults($resultSet) {
        $results = new Pageley_Util_ArrayMap();
        $serializer = Pageley_Serializer_Format::$SQL->getSerializer();
        while($resultSet->hasNext()) {
            $resultSet->next();
            $entity = $serializer->deserialize($resultSet, $this->type);
            $entity->setId($resultSet->get($this->tableName . "_id"));
            $results->add($entity);
        }
        return $results;
    }
}